LIBFILE = libc.a
SRCCFILES := $(shell find . -name "*.c")
SRCSFILES := $(shell find . -name "*.s")
HDRFILES := $(shell find . -name "*.h")
OBJFILES := $(BOOTFILES) $(patsubst %.s,%.o, $(SRCSFILES)) $(patsubst %.c,%.o, $(SRCCFILES))

CCFLAGS = -nostdlib -nostdinc -fno-builtin -m32 -I./include
LDFLAGS = -T Link.ld
ASMFLAGS = -f elf

ARPATH = /usr/cross/bin/i386-elf-ar
CCPATH = /usr/cross/bin/i386-elf-gcc
ASMPATH = nasm

all: $(LIBFILE)

clean:
	@rm $(LIBFILE) $(OBJFILES)

$(LIBFILE): $(OBJFILES)
	@echo "  ar      " $(LIBFILE)
	@$(ARPATH) $(ARFLAGS) $(LIBFILE) $(OBJFILES)
	cp libc.a ../libc/
	cp crt0.o ../libc/
	cp ipc/on_event.o ../libc/
	cp Link.ld ../libc/
	
%.o: %.s
	@echo "  nasm    " $<
	@$(ASMPATH) $(ASMFLAGS) $< -o $@
	
%.o: %.c
	@echo "  gcc     " $<
	@$(CCPATH) $(CCFLAGS) -c $< -o $@